package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.utils.AliyunOSSOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("admin/common")
public class UploadController {
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

  /*  @PostMapping("/upload")
    public Result HandleFileUpload(String name, Integer age , MultipartFile file){
        log.info("文件上传：{}",file);
        return Result.success();
    }*/
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file){
        log.info("文件上传:"+file.getOriginalFilename());
        String url= null;
        try {
            url = aliyunOSSOperator.upload(file.getBytes(), file.getOriginalFilename());
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("文件路径："+url);
        return Result.success(url);
    }
}
